{extend name="public:layout" /}
{block name="title"}清仓商品{/block}
{block name="head"}{/block}
{block name="body"}
<div class="wrapper wrapper-content">
    <div class="ibox">
        <div class="ibox-title">
            <ol class="breadcrumb">
                <li><i class="fa fa-hand-o-right"></i> 清仓商品</li>
            </ol>
        </div>
        <div class="ibox-content">
            <div class="alert alert-warning">
                <strong>说明：</strong>
                <p>1.库存商品不可以当正常商品零售购买。</p>
                <p>2.库存商品出售按库存量一次成交。</p>
                <p>3.库存商品价格必须小于正常售价。</p>
                <p>4.库存商品删除后恢复正常购买流程。</p>
            </div>
            <div class="toolbar">
                <div class="div_show_one_goods">
                    <a class="btn btn-info" onclick="showMoreGoods(this,setMoreGoods);"
                       data-field="sku_ids"
                       data-siteid="{$site_id}"
                       data-url="{:url('plus/Goods/selectmore')}"
                    >
                        选择库存商品
                    </a>
                </div>
            </div>
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th>#</th>
                    <th>商品单价</th>
                    <th>商品库存</th>
                    <th>总价</th>
                    <th>折扣总价</th>
                    <th width="80">操作</th>
                </tr>
                </thead>
                <tbody id="goods_list">
                {volist name="list" id="vo"}
                <tr>
                    <td>
                        <img src="{$vo.goods_thumb}" class="pull-left" style="width:32px;height:32px;margin:4px;" />
                        {$vo.goods_name} {$vo.sku_name}
                    </td>
                    <td>{$vo.simple_price}</td>
                    <td>{$vo.goods_stock}</td>
                    <td>{$vo.total_goods_price}元</td>
                    <td>{$vo.total_clear_price}元</td>
                    <td>
                        <a href="javascript:;" onclick="doAction(this);"
                           data-msg="确认删除吗？" data-url="{:url('delGoods')}" data-params="clear_goods_id={$vo.clear_goods_id}&sku_id={$vo.sku_id}">删除</a>
                    </td>
                </tr>
                {/volist}
                </tbody>
            </table>
        </div>
    </div>
</div>
<script id="set-goods-tpl" type="text/html">
    <form id="skulist_form">
    <table class="table table-bordered">
        <thead>
        <tr>
            <th width="50">#</th>
            <th width="300">商品名称</th>
            <th width="80">库存</th>
            <th width="80">销售价格</th>
            <th width="80">总价</th>
            <th width="120">折扣总价</th>
        </tr>
        </thead>
        <tbody>
        {{ each sku_list }}
        <tr>
            <td>
                <input type="hidden" name="sku_list[{{ $value.sku_id }}][site_id]" value="{{ $value.site_id }}" />
                <input type="hidden" name="sku_list[{{ $value.sku_id }}][site_name]" value="{{ $value.site_name }}" />
                <input type="hidden" name="sku_list[{{ $value.sku_id }}][goods_id]" value="{{ $value.goods_id }}" />
                <input type="hidden" name="sku_list[{{ $value.sku_id }}][sku_id]" value="{{ $value.sku_id }}" />
                <input type="hidden" name="sku_list[{{ $value.sku_id }}][goods_name]" value="{{ $value.goods_name }}" />
                <input type="hidden" name="sku_list[{{ $value.sku_id }}][sku_name]" value="{{ $value.sku_name }}" />
                <input type="hidden" name="sku_list[{{ $value.sku_id }}][simple_price]" value="{{ $value.simple_price }}" />
                <input type="hidden" name="sku_list[{{ $value.sku_id }}][goods_stock]" value="{{ $value.goods_stock }}" />
                <input type="hidden" name="sku_list[{{ $value.sku_id }}][total_goods_price]" value="{{ $value.simple_price*$value.goods_stock }}" />
                <input type="hidden" name="sku_list[{{ $value.sku_id }}][goods_thumb]" value="{{ $value.goods_thumb }}" />
                {{ $value.sku_id }}
            </td>
            <td>
                <img src="{{ $value.goods_thumb }}" class="pull-left" style="width:32px;height:32px;margin:4px;" />
                {{ $value.goods_name }}
            </td>
            <td>{{ $value.goods_stock }}</td>
            <td>{{ $value.simple_price }}</td>
            <td>{{ $value.simple_price*$value.goods_stock }}</td>
            <td>
                <input type="text" class="form-control" name="sku_list[{{ $value.sku_id }}][total_clear_price]" value="{{ $value.simple_price*$value.goods_stock }}" />
            </td>
        </tr>
        {{ /each }}
        </tbody>
    </table>
    <button type="button" class="btn btn-primary btn-large btn-block" onclick="addGoods();">加入活动</button>
    </form>
</script>
{/block}
{block name="script"}
<script>
    In('selectgoods');
    //选取商品回调
    function setMoreGoods(field,sku) {
        In('layer','templete',function () {
            var html = template('set-goods-tpl', sku);
            layer.open({
                type: 1,
                title:false,
                skin: 'layui-layer-rim',
                area:'680px',
                content: html
            });
        })
    }
    //添加商品
    function addGoods() {
        var url = "{:url('addGoods')}";
        var params = $('#skulist_form').serialize();
        $.post(url,params,function (res) {
            if(res.code==1){
                rePage();
            }else{
                alert(res.msg);
            }
        })
    }
</script>
{/block}